package com.jcfk.system.controller;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

import com.jcfk.system.domain.query.SysWorkbenchPageQuery;
import com.jcfk.system.domain.dto.SysWorkbenchPageDTO;
import com.jcfk.system.service.SysWorkbenchPageService;
import com.jcfk.common.core.utils.ExcelUtils;

import java.util.List;

/**
 * 工作台页面
 *
 * @author libinghai
 * @email 35738025@gqq.com
 * @date 2024-01-29
 */
@Api(value = "sysworkbenchpage", tags = {"工作台页面"})
@RestController
@RequestMapping("sysworkbenchpage")
public class SysWorkbenchPageController {
    @Autowired
    private SysWorkbenchPageService sysWorkbenchPageService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<SysWorkbenchPageQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation(value = "分页列表", notes = "分页列表", httpMethod = "POST")
    @PostMapping("/queryByPage")
    public RetPage<SysWorkbenchPageDTO> queryByPage(@RequestBody ReqPageParam<SysWorkbenchPageQuery> requestParam) {
        DataPage<SysWorkbenchPageDTO> page = new DataPage<SysWorkbenchPageDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            SysWorkbenchPageDTO.class);
        page = sysWorkbenchPageService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }

    /**
     * 获取工作台页面列表
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "SysWorkbenchPageQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取工作台页面列表", notes = "获取工作台页面列表", httpMethod = "POST")
    @PostMapping("/getList")
    public RetResult<List<SysWorkbenchPageDTO>> getList(@RequestBody SysWorkbenchPageQuery query){
        List<SysWorkbenchPageDTO> list=sysWorkbenchPageService.getList(query);
        return RetResult.ok(list);
    }


    /**
     *  工作台页面
     * 根据id 查询详情
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "string", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "工作台页面 根据id 查询详情", notes = "工作台页面 根据id 查询详情", httpMethod = "GET")
    @GetMapping("/get/{id}")
    public RetResult<SysWorkbenchPageDTO> get(@PathVariable("id") String id) {
            SysWorkbenchPageDTO item = sysWorkbenchPageService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理工作台页面
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "SysWorkbenchPageDTO", name = "sysWorkbenchPage", value = "", required = true)
    })
    @ApiOperation(value = "添加/更新管理工作台页面", notes = "添加/更新管理工作台页面", httpMethod = "POST")
    @PostMapping("/save")
    @RequestLogHeader(modular = "工作台页面管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid SysWorkbenchPageDTO sysWorkbenchPage) {
        // 数据校验
        RetResult ret = sysWorkbenchPageService.isValid(sysWorkbenchPage);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(sysWorkbenchPage.getId())){
            // 新增
            sysWorkbenchPageService.insert(sysWorkbenchPage);
        } else{
            // 更新
            sysWorkbenchPageService.update(sysWorkbenchPage);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除工作台页面
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "SysWorkbenchPageDTO", name = "sysWorkbenchPage", value = "", required = true)
    })
    @ApiOperation(value = "批量删除工作台页面", notes = "批量删除工作台页面", httpMethod = "POST")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "工作台页面管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody SysWorkbenchPageDTO sysWorkbenchPage) {
        return RetResult.ok(sysWorkbenchPageService.logicDeleteList(sysWorkbenchPage));
    }

}
